package org.wzy.springcloud.feign.handler;

import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 详见org.springframework.boot.autoconfigure.web.DefaultErrorAttributes#getErrorAttributes()实现
 * 可通过 getErrorAttributes() 方法自由封装需要返回给上层应用的异常信息，默认返回如下：
 * {"timestamp":1519565701283,"status":500,"error":"Internal Server Error","exception":"java.lang.NullPointerException","message":"抛异常啦~~~~~~~~~~~~~~~~~~","path":"/person/save"}
 */
@Component
public class DemoErrorAttributesHandler implements ErrorAttributes, HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        System.out.println("进入了resolveException方法了。。。。。。");
        return null;
    }

    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
        System.out.println("进入getErrorAttributes方法......!!!!");
        return null;
    }

    @Override
    public Throwable getError(WebRequest webRequest) {
        System.out.println("试试看这段话会不会被打印出来......");
        return null;
    }
}
